package com.anycl.design.j2ee.servicelocator;

/**
 * 服务定位器，获取服务的统一入口
 */
public class ServiceLocator {
    private static Cache cache;

    static {
        cache = new Cache();
    }

    public static Service getService(String name) {
        // 先从缓存中获取服务
        Service service = cache.getService(name);
        if (service != null)
            return service;
        // 根据名称找到相应服务
        InitialContext context = new InitialContext();
        service = context.lookUp(name);
        cache.addService(service);
        return service;
    }
}
